using UnityEngine;
using System.Collections;

public class MoveOnDirection : CharacterAction
{
	public float speed = 1;
 
	public override void OnActionEnter (Character character)
	{
		character.onDirectionCommand.OnEvent += OnDirectionCommand;
	}

	public override void OnActionExit (Character character)
	{
		character.onDirectionCommand.OnEvent -= OnDirectionCommand;
	}


	public void OnDirectionCommand (Character.DirectionCommand arg)
	{
		Character character = arg.character;
		float direction = arg.direction;
		Vector3 newVelocity = new Vector3(Mathf.Sin(direction * Mathf.Deg2Rad), 0, Mathf.Cos(direction * Mathf.Deg2Rad));
		character.rigidbodyRef.velocity = newVelocity * speed;
	}
}

